﻿
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Dapper;
using DapperExtensions;

namespace Agile.Service.Rbac
{
    ///<summary>
    ///角色表
    ///</summary>
    public interface IRoleService : IRepository<Role>
    {
        void Switch(string Id);
        List<Role> GetRoles(string keyword="");
    }
    ///<summary>
    ///角色表
    ///</summary>
    public partial class RoleService : DapperRepository<Role>, IRoleService
    {
        public List<Role> GetRoles(string keyword="")
        {
            string where = " Category=1 ";
            if (!string.IsNullOrEmpty(keyword))
            {
                where = " and (Name='" + keyword + "' or EnCode='" + keyword + "')";
            }
            var data = GetByAll(where);
            return data;
        }

        public void Switch(string Id)
        {
            var model = GetById(Id);
            if (model != null)
            {
                if (model.Status > 0)
                {
                    model.Status = 0;
                }
                else
                {
                    model.Status = 1;
                }
                Update(model);
            }
        }
    }
}

